import com.google.common.base.Objects;
import com.google.common.collect.ComparisonChain;

/**
 * Created by fgchen on 2017/6/30.
 */
public class User implements Comparable<User> {
    String name;
    Integer age;

    public User(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || !(obj instanceof User)) return false;
        return Objects.equal(this.name, ((User) obj).name) && Objects.equal(this.age, ((User) obj).age);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(this.name, this.age);
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this).add("name", this.name).add("age", this.age).toString();
    }

    @Override
    public int compareTo(User user) {
        return ComparisonChain.start()
                .compare(this.age, user.age)
                .compare(this.name, user.name)
                .result();
    }
}
